package com.ttflutter.tkvideodownloader.api

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import java.io.Serializable

enum class MediaTypeEnum(val type: Int) {
    IMAGE(0),
    VIDEO(1),
    SIDECAR_IMAGE(2)
}
val INS_FLAG = "INS_"
val TK_FLAG = "TK_"
val DOUYIN_FLAG = "DOUYIN_"

/**
 * @author Afra55
 * @date 2020/4/13
 * A smile is the best business card.
 */
@Entity(tableName = "media")
data class MediaEntity(
    @PrimaryKey @ColumnInfo(name = "a") var media_id: String,
    @ColumnInfo(name = "b") val media_type: Int? = MediaTypeEnum.IMAGE.type,
    @ColumnInfo(name = "c") val shortcode: String?,
    @ColumnInfo(name = "d") val display_url: String?,
    @ColumnInfo(name = "e") val video_url: String?,
    @ColumnInfo(name = "g") val caption: String?,
    @ColumnInfo(name = "j") val taken_at_timestamp: String?,
    @ColumnInfo(name = "k") val owner_user_id: String?,
    @ColumnInfo(name = "l") val profile_pic_url: String?,
    @ColumnInfo(name = "m") val username: String?,
    @ColumnInfo(name = "n") val full_name: String?,
    @ColumnInfo(name = "o") val is_private: Boolean?
) : Serializable {
    @ColumnInfo(name = "saved_time")
    var saved_time: Long? = null
    @ColumnInfo(name = "file_name")
    var file_name: String? = null
    @ColumnInfo(name = "music_file_name")
    var music_file_name: String? = null
    @ColumnInfo(name = "has_download")
    var has_download:Boolean? = false

    @ColumnInfo(name = "from", defaultValue = "0")
    var from:Int = 0    // 0 ins, 1 tiktok, 2 douyin

    @ColumnInfo(name = "music_id")
    var musicId:String? = null
    @ColumnInfo(name = "music_name")
    var musicName:String? = null
    @ColumnInfo(name = "music_cover")
    var musicCover:String? = null
    @ColumnInfo(name = "music_url")
    var musicPlayUrl:String? = null

    @ColumnInfo(name = "origin_url")
    var originUrl:String? = null

    override fun toString(): String {
        return "MediaEntity(media_id='$media_id', media_type=$media_type, shortcode=$shortcode, display_url=$display_url, video_url=$video_url, caption=$caption, taken_at_timestamp=$taken_at_timestamp, owner_user_id=$owner_user_id, profile_pic_url=$profile_pic_url, username=$username, full_name=$full_name, is_private=$is_private, saved_time=$saved_time, file_name=$file_name, music_file_name=$music_file_name, has_download=$has_download, from=$from, musicId=$musicId, musicName=$musicName, musicCover=$musicCover, musicPlayUrl=$musicPlayUrl, originUrl=$originUrl)"
    }

    fun laMusicCover():String?{
        return musicCover?:display_url
    }

}